package LoanJFrame;

import Test.Person;
import Test.PersonJPanel;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class LoanJFrame extends JFrame implements ActionListener {

    private DefaultTableModel defaultTableModel;
    private PersonJPanel personJPanelpanel;
    private DefaultTableModel personTable = new DefaultTableModel();
    private JTable table = new JTable(personTable);
    protected JComboBox<String>[] comboBoxes;


    public LoanJFrame(Person[] pers, PersonJPanel personJPanel){
        super("Person");
        this.setSize(700,400);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);//水平分割窗格
        this.getContentPane().add(splitPane);


        //this.getContentPane().add(panel,BorderLayout.NORTH);
        String[] title = {"姓名","出身日期","性别","省份","城市"};
        this.defaultTableModel = new DefaultTableModel(title,10);
        JTable jTable = new JTable(this.defaultTableModel);
        this.getContentPane().add(new JScrollPane(jTable));
        splitPane.add(jTable);



        this.personJPanelpanel = personJPanel;
        splitPane.add(this.personJPanelpanel);
        splitPane.setDividerLocation(200);
        splitPane.setOneTouchExpandable(true);


        JPanel cmdPanel = new JPanel();
        personJPanelpanel.add(cmdPanel,"South");
        String[][] str = {{"添加","删除","删除选中项"},{"查找关键字","排序关键字"},{"姓名","出身日期"}};
        for (int i = 0; i < str[0].length; i++) {
            JButton button = new JButton(str[0][i]);
            button.addActionListener(this);
            cmdPanel.add(button);
        }
        this.comboBoxes = new JComboBox[str[1].length];
        for (int i = 0; i < str[1].length; i++) {
            cmdPanel.add(new JLabel(str[1][i]));
            cmdPanel.add(this.comboBoxes[i] = new JComboBox<>(str[2]));
            this.comboBoxes[i].addActionListener(this);
        }
        this.setVisible(true);
    }
    @Override
    public void actionPerformed(ActionEvent e) {

    }

    public static void main(String[] args) {
        Person[] pers = {new Person("zhang","2020年10月10号","男","江苏","扬州"),
                new Person("lisi","2020年10月11号","男","江苏","扬州")};
        new LoanJFrame(pers,new PersonJPanel());
    }
}
